# 定义一个狗类,里面有一个 列表成员变量(列表的元素是字典), 分别记录了 3种颜色的狗的颜色, 数量,和价格;
#        实现狗的买卖交易方法;  打印输出经过2-3次买卖方法后,剩下的各类狗的数量;

class Dog( object ):

    dogs = []
    def __init__( dog, color, number, price ):
        dog.color = color
        dog.number = number
        dog.price = price
        dog.dogs.append( { dog.color : [ dog.number, dog.price ] } )

    def sell( dog, num ):
        if dog.color == 'black':
            dog.dogs[0][dog.color][0] -= num
        elif dog.color == 'yello':
            dog.dogs[1][dog.color][0] -= num
        elif dog.color == 'white':
            dog.dogs[2][dog.color][0] -= num

    def buy( dog, num ):
        if dog.color == 'black':
            dog.dogs[0][dog.color][0] += num
        elif dog.color == 'yello':
            dog.dogs[1][dog.color][0] += num
        elif dog.color == 'white':
            dog.dogs[2][dog.color][0] += num


black_dogs = Dog( 'black', 18, 500 )
yello_dogs = Dog( 'yello', 20, 200 )
white_dogs = Dog( 'white', 30, 1500 )

black_dogs.sell( 2 )
yello_dogs.sell( 8 )
white_dogs.buy( 10 )

print( black_dogs.dogs )
print( yello_dogs.dogs )
print( white_dogs.dogs )